package com.caojing.haolemai.ui.outlets.outletsSharefragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.caojing.haolemai.R;
import com.caojing.haolemai.bean.OutletsSharefragmentBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/18 0018.
 */
public class OutletsShareFragmentAdapter extends BaseAdapter {
    private List<OutletsSharefragmentBean.ResultsEntity.ResultsEntity1> list;
    private Context context;

    public OutletsShareFragmentAdapter(List<OutletsSharefragmentBean.ResultsEntity.ResultsEntity1> list, Context context) {
        this.list = list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i) != null ? list.get(i) : null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.outletssharefragment_list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//        绑定数据
        OutletsSharefragmentBean.ResultsEntity.ResultsEntity1 outletsInnerResultsEntity = list.get(i);
        String title = outletsInnerResultsEntity.getTitle();
        String imageIndex = outletsInnerResultsEntity.getImageIndex();
        String discount = outletsInnerResultsEntity.getDiscount();
        String startTime = outletsInnerResultsEntity.getStartTime();
        String endTime = outletsInnerResultsEntity.getEndTime();

        //String newStartTime = startTime.substring(startTime.lastIndexOf("1" + 1));
        //String newEndTime = startTime.substring(endTime.lastIndexOf("1" + 1));
        String newStartTime = startTime.substring(5,10)+"--";
        String newEndTime = endTime.substring(5,10);




        Glide.with(context).load(imageIndex).asBitmap().into(holder.imageviewSharefragmentListItem);
        holder.textviewDiscount.setText(discount);
        holder.textviewTitle.setText(title);
        holder.textviewStartTime.setText(newStartTime);
        holder.textviewEndTime.setText(newEndTime);



        return convertView;
    }

   static class ViewHolder {
        @Bind(R.id.imageview_sharefragment_list_item)
        ImageView imageviewSharefragmentListItem;
        @Bind(R.id.textview_discount)
        TextView textviewDiscount;
        @Bind(R.id.textview_title)
        TextView textviewTitle;
        @Bind(R.id.textview_start_time)
        TextView textviewStartTime;
        @Bind(R.id.textview_end_time)
        TextView textviewEndTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
